package aliasMatching.controller;

import aliasMatching.model.MyTableModel;
import java.awt.BorderLayout;

import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

/**
 *
 * @author amendrashrestha
 *
 * This abstract class is responsible for handling the action of popup 
 * and bar menu.
 */
public class EqualityActions extends AbstractAction {

    List userList = new ArrayList();
    List username = new ArrayList();
    MyTableModel tableMdl;
    public JPanel panel;
    CreateGraph graphCreator;
    public static JPanel timeGraph;

    /**
     * This method assign the text and action command to each pop up item.
     * @param text is the item for pop up menu 
     * @param actionCommand track action for the component
     * @parm list is the list of the users
     */
    public EqualityActions(String text, String actionCommand, List IDlist, List userNameList, MyTableModel mdl,
            ImageIcon icon, String toolTip) {

        super(text, icon);
        putValue(Action.ACTION_COMMAND_KEY, actionCommand);
        putValue(Action.SHORT_DESCRIPTION, toolTip);
        tableMdl = mdl;
        userList = IDlist;
        username = userNameList;
        //this.panel = p;
        graphCreator = new CreateGraph();


        /*For passing the user list manually, 
         * Please comment the above userList = list line and uncomment 
        the below userList.add(374) as well as other line
        These numbers are the userID, so you can put any userID that exists in
        our database.*/

//
        /*Friend Equality*/
//        userList.add(374);
//        userList.add(4);
//        userList.add(98);
//        userList.add(366);

        /*Time Equality*/
//         userList.add(61687);
//         userList.add(131131);

    }



    @Override
    public void actionPerformed(ActionEvent e) {
        if ("New".equals(getValue(Action.ACTION_COMMAND_KEY).toString())) {
            New.New(userList, username, tableMdl, CreateGraph.clickedUser, TableActions.panel, TableActions.timeGraph, timeGraph);
        } else if ("Chart".equals(getValue(Action.ACTION_COMMAND_KEY).toString())) {
            timeGraph = graphCreator.createTimegraphPanel(userList);
            TableActions.panel.add(timeGraph, BorderLayout.SOUTH);
            TableActions.panel.updateUI();
            TableActions.panel.repaint();

        } else if ("FriendEquality".equals(getValue(Action.ACTION_COMMAND_KEY).toString())) {
            try {
                new FriendEquality(userList, username, tableMdl);
            } catch (SQLException ex) {
                Logger.getLogger(EqualityActions.class.getName()).log(Level.SEVERE, null, ex);
            }

        } else if ("NameEquality".equals(getValue(Action.ACTION_COMMAND_KEY).toString())) {

            new NameEquality(0.70, 4, userList, username, tableMdl);

        } else if ("ThreadEquality".equals(getValue(Action.ACTION_COMMAND_KEY).toString())) {
            try {
                new ThreadEquality(userList, username, tableMdl);
            } catch (SQLException ex) {
                Logger.getLogger(EqualityActions.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if ("TimeEquality".equals(getValue(Action.ACTION_COMMAND_KEY).toString())) {
            try {
                new TimeEquality(userList, username, tableMdl);
            } catch (SQLException ex) {
                Logger.getLogger(EqualityActions.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if ("StylometricEquality".equals(getValue(Action.ACTION_COMMAND_KEY).toString())) {
            try {
                StylometricEquality se = new StylometricEquality(userList, username, tableMdl);
                se.executeStylo();
            } catch (SQLException ex) {
                Logger.getLogger(EqualityActions.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if ("Exit".equals(getValue(Action.ACTION_COMMAND_KEY).toString())) {
            System.exit(0);
        }
    }
}
